package com.jt.factory;

import com.jt.pojo.User;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Calendar;

public class testFactory {
    @Test
    public void testStaticFactory(){
        ApplicationContext context = new ClassPathXmlApplicationContext("application.xml");
        Calendar calender1 = (Calendar) context.getBean("calender1");
        System.out.println("当前时间 = " + calender1.getTime());
    }

    @Test
    public void testInstanceFactory(){
        ApplicationContext context = new ClassPathXmlApplicationContext("application.xml");
        Calendar calender2 = (Calendar) context.getBean("calendar2");
        System.out.println("当前时间 = " + calender2.getTime());
    }

    @Test
    public void testSpringFactory(){
        ApplicationContext context = new ClassPathXmlApplicationContext("application.xml");
        Calendar calender3 = (Calendar) context.getBean("calendar3");
        System.out.println("当前时间 = " + calender3.getTime());
    }

    @Test
    public void testUser() {
        ApplicationContext context =
                new ClassPathXmlApplicationContext("application.xml");
        context.getBean("user");//创建对象
        context.getBean("user");//创建对象
        context.getBean("user");//创建对象
    }
    @Test
    public void testLifeCycle() {
        ClassPathXmlApplicationContext context =
                new ClassPathXmlApplicationContext("application.xml");
        //获取对象
        User user = (User) context.getBean("user");
        //调用方法
        user.say();
        //容器关闭，对象销毁
        context.close();
    }
}
